import java.util.*;

/**
 *  input：5 4 2 3 6 1  nums
 *         2            k
 *  output：5 6
 */
public class TopK {
    public static void main(String[] args) {
        ArrayList<Integer> array = new ArrayList<Integer>();
        Scanner in = new Scanner(System.in);
        String l = in.nextLine();
        Scanner sc = new Scanner(l);
        while(sc.hasNext()) {
            array.add(sc.nextInt());
        }
        Integer[] arr = new Integer[array.size()];
        arr = array.toArray(arr);
        int k = in.nextInt();
        Integer[] res = topK(arr, k);
        for (Integer integer : res) {
            System.out.print(integer + " ");
        }
    }

    public static Integer[] topK(Integer[] arr, int k) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(k, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                //小顶堆  topK大
                return o1-o2;

                //大顶堆  topK小
                //return o2-o1;
            }
        });

        Integer[] res = new Integer[k];

        for (int i = 0; i < k; i++) {
            priorityQueue.offer(arr[i]);
        }

        for (int i = k; i < arr.length; i++) {
            //if (priorityQueue.peek() < arr[i]){
            if (priorityQueue.peek() < arr[i]){
                priorityQueue.poll();
                priorityQueue.offer(arr[i]);
            }
        }

        for (int i = 0; i < k; i++) {
            res[i] = priorityQueue.poll();
        }
        return res;
    }
}
